package cPanes;


import java.awt.Component;
import java.awt.event.ActionEvent;
import java.awt.event.MouseEvent;

import javax.swing.JTextArea;
import javax.swing.JTextPane;

import core.PassListener;


/**
 * A basic text pane, for typing without any special formatting.
 */
public class TextPane extends CPane{
	private JTextPane t = new JTextPane();
	/*
	 * Sets the basic properties of the Panel, adds the PassListener to the text area.
	 */
	public TextPane(){
		super();
		this.setName("TXT");
		PassListener pl = new PassListener();
		this.setLayout(null);
		t.setLocation(2, 2);
		t.setSize(this.getWidth()-4, this.getHeight()-4);
		t.addMouseListener(pl);
		t.addMouseMotionListener(pl);
		this.setWidth(200);
		this.setHeight(200);
		resizeContents(this.getWidth(), this.getHeight());
		this.add(t);
	}
	/**
	 * Resizes the text area, leaving room for the border.
	 */
	void resizeContents(int owidth, int oheight) {
		t.setSize(this.getWidth()-4, this.getHeight()-4);
	}
	
	public void menuActions(ActionEvent e){
		//No context menu actions
	}
	
	void mouseActions(MouseEvent e) {
		//No special mouse functionality	
	}
	
	void mouseActions(MouseEvent e, String type) {
		//No special mouse functionality	
	}

	/**
	 * Sets the text of the pane, replacing ':%:' with a new line
	 */
	public void openSave(String s) {
		String temp="";
		temp = s.replaceAll(":%:", "\n");
		t.setText(temp);
	}
	/**
	 * Returns the text of the pane, replacing new lines with  ':%:'
	 */
	public String returnSave() {
		String s = t.getText().replaceAll("\n", ":%:");
		return s;
	}
	/**
	 * Gets a reference to the text area of this pane.
	 * @return A reference to the JTextArea on this pane.
	 */
	public JTextPane getTextArea(){
		return t;
	}

}
